class Solution {//leetcode56——合并区间
public:
    vector<vector<int>> merge(vector<vector<int>>& intervals) {
        sort(intervals.begin(),intervals.end(),[](vector<int> lhs,vector<int> rhs)->bool{
            return lhs[0]<rhs[0];
        });
        int n=intervals.size();
        int cur=0;
        vector<vector<int>> ret;
        ret.push_back(intervals[0]);
        for(int i=1;i<n;i++){
            int begin1=ret[cur][0],end1=ret[cur][1];
            int begin2=intervals[i][0],end2=intervals[i][1];
            if(end1>=begin2&&end2>=end1) ret[cur]={begin1,end2};
            else if(end1>=begin2&&end2<=end1) ret[cur]={begin1,end1};
            else if(begin2>end1){
                ret.push_back({begin2,end2});
                cur++;
            } 
        }
        return ret;
        
    }
};